package com.wing.bill.controller.admin;

import com.wing.bill.service.CabinetFormService;
import com.wing.bill.service.WorkshopReportService;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.web.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Validated
@Api(value = "Admin-刀具柜报废报表", tags = "#/bill/scrapReport")
@RestController("scrapReportController")
@RequestMapping("bill/admin/scrapReport")
@RequiredArgsConstructor
public class ScrapReportController {

    private final WorkshopReportService workshopReportService;
    private final CabinetFormService cabinetFormService;

    final String dateType = "before";//当前[current]/往前推一周、月[before]（用于业务判断获取当前日期）

    @ApiOperation(value = "顶部趋势图", notes = "报废统计(按天)")
    @GetMapping("/list")
    public JsonResult list(
            @RequestParam("param") String param //柱状图饼状图的下拉选 不同的选项 qua 数量 money 金额
    ){

        String code = JwtUtils.getEnterpriseCode();
        return cabinetFormService.getSpecStatisticsByDay(code,param,3);
    }

    @ApiOperation(value = "顶部格子数据", notes = "报废物料数据统计")
    @GetMapping("/topCell")
    public JsonResult topCell(
            @RequestParam("type")String type//012 当日当周当月
            ,@RequestParam("startTime")String startTime//时间搜索 开始时间
            ,@RequestParam("endTime")String endTime//时间搜索 结束时间
            ,@RequestParam("click")String click//顶部数据点击
            ,@RequestParam("mainCabCode") String mainCabCode //主柜选择
    ){
        String code = JwtUtils.getEnterpriseCode();
        return cabinetFormService.list6(type,dateType,startTime,endTime,Integer.valueOf(click),code,mainCabCode);
    }

    @ApiOperation(value = "中部第一个图", notes = "报废物料(按人员)")
    @GetMapping("/midFirstChart")
    public JsonResult midFirstChart(
            @RequestParam("type")String type//012 当日往前一周往前一月
            ,@RequestParam("startTime")String startTime//时间搜索 开始时间
            ,@RequestParam("endTime")String endTime//时间搜索 结束时间
            ,@RequestParam("mainCabCode") String mainCabCode //主柜选择
    ){
        return cabinetFormService.recycleFirstChart(type,dateType,startTime,endTime,JwtUtils.getEnterpriseCode(),mainCabCode);
    }

    @ApiOperation(value = "中部第二个图", notes = "报废物料规格型号占比")
    @GetMapping("/midSecondChart")
    public JsonResult midSecondChart(
            @RequestParam("type")String type//012 当日当周当月
            ,@RequestParam("startTime")String startTime//时间搜索 开始时间
            ,@RequestParam("endTime")String endTime//时间搜索 结束时间
            ,@RequestParam("mainCabCode") String mainCabCode //主柜选择
            ,@RequestParam("param") String param //柱状图饼状图的下拉选 不同的选项 qua 数量 money 金额
    ){
        return cabinetFormService.getSpecMaterialModelComparison(type,dateType,startTime,endTime,JwtUtils.getEnterpriseCode(),mainCabCode,param,3);
    }

    @ApiOperation(value = "中部第三个图", notes = "报废原因统计")
    @GetMapping("/midThirdChart")
    public JsonResult midThirdChart(
            @RequestParam("type")String type//012 当日当周当月
            ,@RequestParam("startTime")String startTime//时间搜索 开始时间
            ,@RequestParam("endTime")String endTime//时间搜索 结束时间
            ,@RequestParam("mainCabCode") String mainCabCode //主柜选择
            ,@RequestParam("brandId")String brandId //品牌id
            ,@RequestParam("devCode")String devCode //机台
    ){
        return cabinetFormService.recycleSixthChart(type,dateType,startTime,endTime,brandId,devCode,mainCabCode,3);
    }

    @ApiOperation(value = "中部第四个图", notes = "报废物料(按设备)")
    @GetMapping("/midFourthChart")
    public JsonResult midFourthChart(
            @RequestParam("type")String type//012 当日往前一周往前一月
            ,@RequestParam("startTime")String startTime//时间搜索 开始时间
            ,@RequestParam("endTime")String endTime//时间搜索 结束时间
            ,@RequestParam("mainCabCode") String mainCabCode //主柜选择
    ){
        return cabinetFormService.recycleFourthChart(type,dateType,startTime,endTime,JwtUtils.getEnterpriseCode(),mainCabCode);
    }

    @ApiOperation(value = "中部第五个图", notes = "报废物料(按车间)")
    @GetMapping("/midFifthChart")
    public JsonResult midFifthChart(
            @RequestParam("type")String type//012 当日往前一周往前一月
            ,@RequestParam("startTime")String startTime//时间搜索 开始时间
            ,@RequestParam("endTime")String endTime//时间搜索 结束时间
            ,@RequestParam("mainCabCode") String mainCabCode //主柜选择
    ){
        return cabinetFormService.recycleSecondChart(type,dateType,startTime,endTime,JwtUtils.getEnterpriseCode(),mainCabCode);
    }

    @ApiOperation(value = "底部列表", notes = "报废记录")
    @GetMapping("/data")
    public PageResult data(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "desc") String order
            ,@RequestParam("type")String type//012 当日当周当月
            ,@RequestParam("startTime")String startTime//时间搜索 开始时间
            ,@RequestParam("endTime")String endTime//时间搜索 结束时间
    ){
        return cabinetFormService.data6(type,dateType,startTime,endTime,page,limit,sort,order);
    }
}
